#include "DataStructure/Input/Element/CONRODData.h"

#include "DataStructure/Common/Validation.h"
#include "DataStructure/Input/Solver/DOFDirections.h"

using namespace SG::DataStructure::FEM;

/** 计算杆单元激活自由度
 *
 * 当仅有截面积非零，杆只能抵抗拉压变形
 * 当仅有扭转刚度系数非零，杆只能抵抗扭转变形
 */
DofSet CONRODData::GetActiveDofs () const
{
    if (m_A > 1.0e-12 && m_J > 1.0e-12)
    {
        return getAllNodeDofs ();
    }

    if (m_A > 1.0e-12)
    {
        return { DOF_Ux, DOF_Uy, DOF_Uz };
    }

    if (m_J > 1.0e-12)
    {
        return { DOF_Rotx, DOF_Roty, DOF_Rotz };
    }

    // 此时截面积和扭转刚度系数均为0.0
    return {};
}

/// @brief 判断单元数据是否相等
bool SG::DataStructure::FEM::operator== (const CONRODData &a, const CONRODData &b)
{
    if (a.m_id != b.m_id)
    {
        return false;
    }
    if (a.m_g[0] != b.m_g[0])
    {
        return false;
    }
    if (a.m_g[1] != b.m_g[1])
    {
        return false;
    }
    if (a.m_mId != b.m_mId)
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_A, b.m_A))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_J, b.m_J))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_C, b.m_C))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_NSM, b.m_NSM))
    {
        return false;
    }
    if (a.m_domainId != b.m_domainId)
    {
        return false;
    }
    return true;
}